//189000950 顾啟思
var ad_width = "100px";
var ad_height = "250px";
var ad_img = "./ad1.jpg";
var ad_img1 = "./ad1.jpg";
var ad2_img = "./ad2.jpg";
var close_img = "./close.png";

// 创建广告容器的div
var ad_left = document.createElement("div");
ad_left.style.width = ad_width;
ad_left.style.height = ad_height;
ad_left.style.padding = "0px";
ad_left.style.position = "absolute";
ad_left.style.left = "30px";
ad_left.style.top = "20px";

// 创建 img 元素，并加入到 ad_left 中，作为广告图片
var adimg = document.createElement("img");
adimg.src = ad_img;
ad_left.appendChild(adimg);


// 创建关闭按钮，并加入到 ad_left 中
var closeimg = document.createElement("img");
closeimg.src = close_img;
closeimg.style.width = "50px";
closeimg.style.position = "relative";
closeimg.style.left = "50px";
closeimg.style.top = "-20px";
closeimg.style.cursor = "pointer";
ad_left.appendChild(closeimg);

// 将 ad_left 添加到 html 中
document.documentElement.appendChild(ad_left);

// 注册事件，实现关闭广告功能
closeimg.addEventListener("click",function(){
    closeimg1.style.display = "none";
    closeimg.style.display = "none";
    adimg.style.display = "none";
    adimg1.style.display = "none";
})

// 编写代码，实现对联广告随滚动条移动。
window.addEventListener("scroll",function(){
    var st1 = this.document.documentElement.scrollTop || this.document.body.scrollTop;
    ad_left.style.top = (st1 + 20) + "px";
    ad_right.style.top = (st1 + 20) + "px";
});

// 克隆右边的对联
var ad_right = document.createElement("div");
ad_right.style.width = ad_width;
ad_right.style.height = ad_height;
ad_right.style.padding = "0px";
ad_right.style.position = "absolute";
ad_right.style.right = "30px";
ad_right.style.top = "20px";

var adimg1 = document.createElement("img");
adimg1.src = ad_img1;
ad_right.appendChild(adimg1);
var closeimg1 = document.createElement("img");
closeimg1.src = close_img;
closeimg1.style.width = "50px";
closeimg1.style.position = "relative";
closeimg1.style.left = "50px";
closeimg1.style.top = "-20px";
closeimg1.style.cursor = "pointer";
ad_right.appendChild(closeimg1);
document.documentElement.appendChild(ad_right);
closeimg1.addEventListener("click",function(){
    closeimg1.style.display = "none";
    closeimg.style.display = "none";
    adimg.style.display = "none";
    adimg1.style.display = "none";
});

// 右下角广告
var ad2_width = "300px";
var ad2_height = "250px";

var ad2 = document.createElement("div");
ad2.style.width = ad2_width;
ad2.style.height = ad2_height;
ad2.style.padding = "0px";
ad2.style.position = "absolute";
ad2.style.right = "0px";
ad2.style.bottom = "0px";

var ad2_img1 = document.createElement("img");
ad2_img1.src = ad2_img;
ad2.appendChild(ad2_img1);

var closeimg2 = document.createElement("img");
closeimg2.src = close_img;
closeimg2.style.width = "50px";
closeimg2.style.position = "relative";
closeimg2.style.left = "250px";
closeimg2.style.top = "-255px";
closeimg2.style.cursor = "pointer";
ad2.appendChild(closeimg2);
closeimg2.addEventListener("click",function(){
    closeimg2.style.display = "none";
    ad2.style.display = "none";
});
// 延迟出现
function show(){
    document.documentElement.appendChild(ad2);
}
setInterval(show,2000);
// 编写代码，实现右下角广告随滚动条移动。
window.addEventListener("scroll",function(){
    var st1 = this.document.documentElement.scrollTop || this.document.body.scrollTop;
    ad2.style.top = (st1 + 457) + "px";
});
